<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------


// 应用公共文件
function show($status, $message, $data=array()){
    $ret = array(
        'status' => $status,
        'message' => $message,
        'data' => $data
    );
    exit(json_encode($ret));
}

function getMd5Password ($password) {
    return md5($password . config('MD5_PRE'));
}

function getMenuType ($type) {
    return $type == 1 ? '后台菜单' : '前端导航';
}

function status ($status) {
    if ($status == 0) {
        $str = '关闭';
    }elseif ($status == 1) {
        $str = '正常';
    }elseif ($status == -1) {
        $str = '删除';
    }
    return $str;
}

function getAdminMenuUrl($nav){
    $url = '/admin/'.$nav['c'].'/'.$nav['f'];
    if($nav['f'] == 'index') {
        $url = '/admin/'.$nav['c'];
    }
    return $url;
}

function getActive($navc) {
    $request = \think\Request::instance();
    $c = strtolower($request->controller());
    if(strtolower($navc) == $c) {
        return 'class="active"';
    }
    return '';
}

function showKind($status, $data) {
    header('Content-type:application/json;charset=UTF-8');
    if ($status == 0) {
        exit(json_encode(array(
                'error' => 0,
                'url' => $data
            )));
    }
    exit(json_encode(array(
        'error' => 1,
        'message' => '上传失败'
    )));
}


function getLoginUsername() {
    $account = session('adminUser.username', '', 'think');
    return $account ? $account : '';
}

function getCatName ($navs, $id){
    foreach ($navs as $nav) {
        $navList[$nav['menu_id']] = $nav['name'];
    }
    return isset($navList[$id]) ? $navList[$id] : '';
}
function getCopyFromById ($id){
    $copyFrom = config('COPY_FROM');
    return $copyFrom[$id] ? $copyFrom[$id] : '';
}
function isThumb($thumb){
    if($thumb) {
        return '<span style="color: red">有</span>';
    }
    return '无';
}